import time
from page.mailListPage import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from base.basePage import BasePage
from tools.myLogger import logger

class MailListPage(BasePage):

    def __init__(self, driver):
        super().__init__(driver)

    def into_mail_list_page(self):
        """
        进入通讯录页面
        :return:
        """
        logger.info("点击进入通讯录界面")
        self.my_get_url("https://work.weixin.qq.com/wework_admin/frame#index")
        time.sleep(2)
        self.my_click(MailListElement.mail_list_button)

    def add_org(self, org_name, parent_org=None, is_confirm=True):
        """
        新增部门的业务操作步骤
        :param org_name:
        :param parent_org:
        :param is_confirm:
        :return:
        """
        logger.info("开始执行新增部门操作")
        self.my_click(MailListElement.add_button)
        self.my_click(MailListElement.add_org_button)
        self.my_send_keys(MailListElement.org_name_input_box, org_name)
        if parent_org:
            self.my_click(MailListElement.choies_parent_org_down_box)
            self.my_click((MailListElement.choies_parent_org[0], MailListElement.choies_parent_org[1].format(parent_org)))
        # time.sleep(5)
        if is_confirm:
            self.my_click(MailListElement.confirm_button)
        else:
            self.my_click(MailListElement.cancel_button)

    def create_org_get_alrt(self):
        return self.my_get_text(MailListElement.parent_org_alrt)